package com.tianqu.tms.www.member.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.entity.User;
import com.tianqu.tms.www.member.viewhelper.MemberInputViewHelper;
/**
 * 会员信息查看会员登录信息Action
 * 
 * @author tianshifu
 *
 */
public class MemberUDLoginDetailAction extends TmsAction {

	private static final String MEMBERID = "memId";//会员ID
	
	private static final String LOGINSTATUSDATA = "loginStatusData";//会员账户状态
	
	private static final String ZC = "正常";
	
	private static final String SC = "删除";
	
	private static final String JY = "禁用";
	
	private Logger logger = Logger.getLogger(MemberUDLoginDetailAction.class);
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String memberId = ""; 
		//从前台获取会员ID
		if(request.getParameter(MEMBERID) != null){
			memberId = request.getParameter(MEMBERID);
		}else{
			memberId = (String)uc.getAttribute(MEMBERID);
		}
		
		uc.removeAttribute(MEMBERID);
		uc.setAttribute(MEMBERID, memberId);
		// 通过memberID获取userID
		Member entity = Member.getInstance();
		entity = entity.findMemberInfoByMemId(memberId);
		
		String userId = entity.getUserId();//用户ID
		
		User user = new User();
		
		user = user.getUserProfileByLoginid(userId, TmsConstants.BLANK);
		
		//根据userID去用户表中查询用户信息 ----------状态
		
		MemberInputViewHelper view = new MemberInputViewHelper();
		view.setUserId(userId);
		view.setMemberId(String.valueOf(entity.getMemId()));
		
		// 会员的登录状态需要转换
		if(user.getFlag() == 1)
		{
			view.setMemStatus(ZC);
		}
		if(user.getFlag() == 2)
		{
			view.setMemStatus(SC);
		}
		if(user.getFlag() == 3)
		{
			view.setMemStatus(JY);
		}
		
		request.setAttribute(TmsConstants.VIEWHELP,view);
		uc.setAttribute(TmsConstants.VIEWHELP, view);//供修改用
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
